from sqlalchemy import Column,Table,CHAR,FLOAT,ForeignKey
from sqlalchemy.sql.expression import null
from ..data import meta

from pydantic import BaseModel
from typing import Optional
from enum import Enum
from .student import student_table

WE_information_table=Table(
    'WE_information',meta,
    Column(
        'WE_ID',CHAR(60),
        primary_key=True,
        nullable=False,
        unique=True,
    ),
    Column(
        'W_amount',FLOAT,
        nullable=False,
    ),
    Column(
        'E_amount',FLOAT,
        nullable=False,
    ),
    Column(
        'bel_b_name',CHAR(60),
        ForeignKey('building.building_id'),
        nullable=True,
    ),
    Column(
        'bel_d_number',CHAR(60),
        nullable=True,
    ),
    Column(
        'money',FLOAT,
        nullable=False,
    ),
    Column(
        'paid_from_S_ID',CHAR(60),
        ForeignKey('student.s_id'),
        nullable=True,
    ),
    Column(
        'paid_status',CHAR(60),
        nullable=False,
    ),
    Column(
        'paid_time',CHAR(60),
        nullable=True,
    )
)

class WeInformationType(str,Enum):
    pending="未缴费"
    finished="已支付"


class WeInformationInDB(BaseModel):
    WE_ID:str
    # created_time:str
    W_amount:float
    E_amount:float
    bel_b_name:str
    bel_d_number:str
    money:float
    paid_from_S_ID:Optional[str]
    paid_status:WeInformationType
    paid_time:Optional[str]


repair_information_table=Table(
    'repair_information',meta,
    Column(
        'repair_ID',CHAR(60),
        primary_key=True,
        nullable=False,
        unique=True,
    ),
    Column(
        'repair_item',CHAR(60),
        nullable=False,
    ),
    Column(
        'report_from_B_name',CHAR(60),
        ForeignKey('building.building_id'),
        nullable=False,
    ),
    Column(
        'report_from_D_number',CHAR(60),
        nullable=False,
    ),
    Column(
        'report_S_name',CHAR(60),
        nullable=False,
    ),
    Column(
        'report_phone_number',CHAR(60),
        nullable=False,
    ),
    Column(
        'report_time',CHAR(60),
        nullable=False,
    ),
    Column(
        'repair_status',CHAR(60),
        nullable=False,
    )
)


class HandleType(str,Enum):
    accept="同意"
    refused="拒绝"


class RepairInformationType(str,Enum):
    pending="待审批"
    accepted="受理中"
    rejected="拒绝受理"


class RepairInformationInDB(BaseModel):
    repair_ID:str
    repair_item:str
    report_from_B_name:str
    report_from_D_number:str
    report_S_name:str
    report_phone_number:str
    report_time:str
    repair_status:str